<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars
define("PRIMARY_KEY","act_nr_id");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_actnrlist.php";
$FileTemplate  = "ais_transaction_actnrlist_entryadvance_list.html";

$PageSize      = 10 ;
$TableName     = "tbljoborder_costing";
$HTMLGridList  = "ActivityNRGrid";

//************ FORM ACTION **************
    if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
    }

$PreserveGet = GetQueryString("All", array("PageNum"));
//Initiate Database Table For Search;
$FNama = GetParam("nameSearch","");
$FCode = GetParam("codeSearch","");

$temp_no_urut = GetParam("no_urut","");
$jo_ido = GetParam("jo_id","");
$staff_code = GetParam("staff_code","");
$curr_id = GetParam("curr_id","");

//Select Kurs Rate

if(!empty($temp_no_urut))
{
  $no_urut = GetParam("no_urut","");
}
else
{
   $no_urut = "";
}

$FormName = GetParam("FormName","");
//******* DATABASE FORM QUERY ***********
$SQL = "SELECT *, d.skada as skada_act FROM ".$TableName." a
        JOIN tblservices b ON a.services_id = b.services_id
        JOIN tblactivity_nr c ON a.activities_id = c.act_nr_id
        JOIN tblactivity_setup d ON a.activities_id = d.act_nr_id
        JOIN tblshipping_activity e ON (a.activities_id = e.activities_id AND a.jo_id = e.jo_id)
        ";


if ($FNama)
    if (strlen($WHERE)) $WHERE .= " AND "." actname like '".$FNama."%'";
    else $WHERE .= " actname like '".$FNama."%'";
if ($FCode)
    if (strlen($WHERE)) $WHERE .= " AND "." actcode like '".$FCode."%'";
    else $WHERE .= " actcode like '".$FCode."%'";

    if (strlen($WHERE)) $WHERE = " WHERE a.jo_id = '".$jo_ido."' AND paid_ref='staff' AND bs_status <> 'Y' AND a.paid_to_code = '".$staff_code."' AND curr='".$curr_id."' AND a.jo_costing_appv_status = 'approved_2' AND ".$WHERE;
    else $WHERE = " WHERE a.jo_id = '".$jo_ido."' AND paid_ref='staff' AND bs_status <> 'Y' AND a.paid_to_code = '".$staff_code."' AND curr='".$curr_id."' AND a.jo_costing_appv_status = 'approved_2' ";



$SQL = $SQL.$WHERE;
$SQL.= " GROUP BY e.activities_id ";




//COUNT

$WHERE = "";

$SQLCount = "SELECT count(*) FROM ".$TableName." a
        JOIN tblservices b ON a.services_id = b.services_id
        JOIN tblactivity_nr c ON a.activities_id = c.act_nr_id
        JOIN tblactivity_setup d ON a.activities_id = d.act_nr_id
        JOIN tblshipping_activity e ON (a.activities_id = e.activities_id AND a.jo_id = e.jo_id)
        ";


if ($FNama)
    if (strlen($WHERE)) $WHERE .= " AND "." actname like '".$FNama."%'";
    else $WHERE .= " actname like '".$FNama."%'";
if ($FCode)
    if (strlen($WHERE)) $WHERE .= " AND "." actcode like '".$FCode."%'";
    else $WHERE .= " actcode like '".$FCode."%'";

    if (strlen($WHERE)) $WHERE = " WHERE a.jo_id = '".$jo_ido."' AND paid_ref='staff' AND bs_status <> 'Y' AND a.paid_to_code = '".$staff_code."' AND curr='".$curr_id."' AND a.jo_costing_appv_status = 'approved_2' AND ".$WHERE;
    else $WHERE = " WHERE a.jo_id = '".$jo_ido."' AND paid_ref='staff' AND bs_status <> 'Y' AND a.paid_to_code = '".$staff_code."' AND curr='".$curr_id."' AND a.jo_costing_appv_status = 'approved_2' ";



$SQLCount = $SQLCount.$WHERE;
$SQLCount.= " GROUP BY e.activities_id ";




//******* SHOW FORM CONTENT *********


$SQLGetKurs = "SELECT * FROM ais_kurssi WHERE curr = 'USD' ORDER BY tglbkt DESC";
$ResultGetKurs  = $DBConnection->dbc->get_row($SQLGetKurs,ARRAY_A);

$kursUSD = $ResultGetKurs['rate'];


//$PageNum = 1;
//$RecCnt = $DBConnection->dbc->get_var($SQLCount) ;
//if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");
//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
}


$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();



?>
